<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        
        class Watcher {
            constructor(handler) {
                this.update = handler
            }
        }

        class Dep {
            constructor() {
                this.subs = []
            }
            addSub(sub) {
                if (sub && sub.update) {
                    this.subs.push(sub)
                }
            }
            notify() {
                this.subs.forEach(sub => {
                    sub.update()
                })
            }
        }

        let dep = new Dep()
        let watcher = new Watcher(() => {
            console.log(213);
        })
        let watcher1 = new Watcher(() => {
            console.log(2133);
        })
        dep.addSub(watcher)
        dep.addSub(watcher1)
        dep.notify()
    </script>
</body>
</html>